package org.wzy.design.patterns.prototype.simple;

import java.util.ArrayList;

public class ConcreatePrototype implements Cloneable {

	private int age;

	private String name;
	
	public ArrayList<String> arrayList = new ArrayList<>();
	
	@SuppressWarnings("unchecked")
	protected Object clone() throws CloneNotSupportedException {
		ConcreatePrototype prototype = null;
		try {
			prototype = (ConcreatePrototype) super.clone();
			prototype.arrayList = (ArrayList<String>) arrayList.clone();
			
			// 克隆是基于字节码的
			// 用反射或者循环
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return prototype;
	}
	
	// 假设这里定义了100+个属性

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
